package com.mes.inventory.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Part;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;
import com.mes.task.domain.Task;

/**
 * <p>
 * Iodetail实体，代表库存出入库明细。
 * </p>
 * 
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "I_IODETAIL")
@BatchSize(size=20)
@Lazy(value=true)
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class InvIODetail extends BasicModel
{
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name="UNIQUEID")
	protected String uniqueId;
	
	@Column(name="INVIOID")
	protected String invIOUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="INVIOID",insertable=false,updatable=false)
	protected InvIO invIO;

	@Column(name="SEQ")
	protected Integer seq;

	@Column(name="MATERIALUSN")
	protected String materialUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MATERIALUSN",insertable=false,updatable=false)
	protected Material material;

	@Column(name="BINID")
	protected String warebinUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="BINID",insertable=false,updatable=false)
	protected Warebin warebin;

	/**
	 * 出入库数量
	 */
	@Column(name="IOQTY")
	protected Float ioQty;
	/**
	 * 单位
	 */
	@Column(name="UOM")
	protected String uom;
	/**
	 * 金额
	 */
	@Column(name="AMOUNT")
	protected Float amount;
	/**
	 * 单价
	 */
	@Column(name="UNITPRICE")
	protected Float unitPrice;

	/**
	 * 税率
	 */
	@Column(name="TAXRATE")
	protected Float taxRate;
	/**
	 * 含税单价
	 */
	@Column(name="TAXUNITPRICE")
	protected Integer taxUnitPrice;
	/**
	 * 含税金额
	 */
	@Column(name="TAXAMOUNT")
	protected Integer taxAmount;

	@Column(name="PART_NUMBER")
	protected String partUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PART_NUMBER",insertable=false,updatable=false)
	protected Part part;
	
	// 对应物料的图号
	@Column(name = "PART_DRAWINGID")
	protected String partDrawingId;
	// 对应物料的名称
	@Column(name = "PART_NAME")
	protected String partName;
	// 对应物料的版次
	@Column(name = "PART_VERSIONID")
	protected String partVersionId;
	// 对应物料的规格
	@Column(name = "PART_DESCRIPTION")
	protected String partDescription;
	// 对应物料的类型
	@Column(name = "PART_TYPE")
	protected String materialType;
	
	//批次
	@Column(name="BATCHNUM")
	protected String batchnum;
	//行号
	@Column(name="SN")
	protected String sn;
	
	/**
	 * 申请数量
	 */
	@Column(name="APPLYQTY")
	protected Float applyqty;
	/**
	 * 失效日期
	 */
	@Column(name="INVALID_DATE")
	protected Date invalidDate;
	/**
	 * 定检日期
	 */
	@Column(name="CHECKUP_DATE")
	protected Date checkupDate;
	/**
	 * 维护日期（油封。。。）
	 */
	@Column(name="MAINTENANCE_DATE")
	protected Date maintenanceDate;
	/**
	 * 对于借用出库的预计归还日期
	 */
	@Column(name="PLAN_RETURN_DATE")
	protected Date planReturnDate;
	/**
	 * 对于借用出库的归还日期
	 */
	@Column(name="RETURN_DATE")
	protected Date returnDate;
	/**
	 * 对于借用出库的已归还数量
	 */
	@Column(name="RETURN_QTY")
	protected Float returnQty;
	/**
	 * 对于借用出库的是否已经全部归还标志
	 */
	@Column(name="IS_FINISH_RETURNING")
	protected Integer isFinishReturning;
	/**
	 * 对于借用出库的未全部归还原因
	 */
	@Column(name="NOT_ALL_RETURNED_REASON")
	protected String notAllReturnedReason;
	/**
	 * 对于借用出库的未归还数量
	 */
	@Column(name="NOT_RETURN_QTY")
	protected Integer notReturnQty;
	/**
	 * 对于借用出库的关联单据号
	 */
	@Column(name="RELATIONID")
	protected String relationId;
	/**
	 * 对于借用出库的本次归还数量
	 */
	@Transient
	protected Float curReturnQty;
	
	/**
	 * 拒绝类型描述 301：过程卡前期工序盖章不全，漏工序 205：表面存在研磨膏、油渍 303：过程记录控制表或计量单等加工过程原始记录提供不全
	 * 302：过程卡或MES显示数量与实物数量不符 203：磕碰伤 201：有毛刺 204：清洗不干净 102：零件摆放拥挤，容易造成碰伤
	 * 101：零件混装,分不清批次 202：有锈蚀
	 * 
	 * @return
	 */
	@Column(name="REFUSETYPE")
	protected String refuseType;
	
//	@ForeignKey(name="null")
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumnsOrFormulas(value={
//			@JoinColumnOrFormula(column=@JoinColumn(name="TASKSTATE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
//			@JoinColumnOrFormula(formula=@JoinFormula(value="'refusetype'", referencedColumnName="TYPESNAME"))
//	})
//	protected TypesData refuseTypeDesc;
	
	/**
	 * 生成厂家编号
	 */
	@Column(name = "SUPPLIER")
	protected String supplierUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SUPPLIER", insertable = false, updatable = false)
	protected Dept supplier;


	/** default constructor */
	public InvIODetail()
	{
	}

	/**
	 * 获取出入库表头编号
	 * 
	 * @return
	 */
	
	public String getInvIOUid()
	{
		return invIOUid;
	}

	/**
	 * 设置出入库表头编号
	 * 
	 * @param invIOUid
	 */
	public void setInvIOUid(String invIOUid)
	{
		this.invIOUid = invIOUid;
	}

	/**
	 * 获取出入库表头对象
	 * 
	 * @return
	 */
	
	public InvIO getInvIO()
	{
		return invIO;
	}

	/**
	 * 设置出入库表头对象
	 * 
	 * @param invIo
	 */
	public void setInvIO(InvIO invIO)
	{
		this.invIO = invIO;
	}

	/**
	 * 获取行号
	 * 
	 * @return
	 */
	
	public Integer getSeq()
	{
		return seq;
	}

	/**
	 * 设置行号
	 * 
	 * @param seq
	 */
	public void setSeq(Integer seq)
	{
		this.seq = seq;
	}

	/**
	 * 获取物料唯一编号
	 * 
	 * @return
	 */
	
	public String getMaterialUid()
	{
		return materialUid;
	}

	/**
	 * 设置物料唯一编号
	 * 
	 * @param materialUid
	 */
	public void setMaterialUid(String materialUid)
	{
		this.materialUid = materialUid;
	}

	/**
	 * 获取物料对象
	 * 
	 * @return
	 */
	
	public Material getMaterial()
	{
		return material;
	}

	/**
	 * 设置物料对象
	 * 
	 * @param material
	 */
	public void setMaterial(Material material)
	{
		this.material = material;
		// 设置对象同时设置其对象uuid
		// this.materialUid=material.getUuid();
	}

	/**
	 * 获取柜位编号
	 * 
	 * @return
	 */
	
	public String getWarebinUid()
	{
		return warebinUid;
	}

	/**
	 * 设置柜位编号
	 * 
	 * @param warebinUid
	 */
	public void setWarebinUid(String warebinUid)
	{
		this.warebinUid = warebinUid;
	}

	/**
	 * 获取柜位对象
	 * 
	 * @return
	 */
	
	public Warebin getWarebin()
	{
		return warebin;
	}

	/**
	 * 设置柜位对象
	 * 
	 * @param invWarebin
	 */
	public void setInvWarebin(Warebin warebin)
	{
		this.warebin = warebin;
		// 设置对象同时设置其对象uuid
		this.warebinUid = warebin.getUuid();
	}

	/**
	 * 获取出入库数量
	 */
	
	public Float getIoQty()
	{
		return ioQty;
	}

	/**
	 * 设置出入库数量
	 * 
	 * @param ioqty
	 */
	public void setIoQty(Float ioQty)
	{
		this.ioQty = ioQty;
	}

	/**
	 * 获取总金额
	 * 
	 * @return
	 */
	
	public Float getAmount()
	{
		return amount;
	}

	/**
	 * 设置总金额
	 * 
	 * @param amount
	 */
	public void setAmount(Float amount)
	{
		this.amount = amount;
	}

	/**
	 * 获取单位
	 * 
	 * @return
	 */
	
	public String getUom()
	{
		return uom;
	}

	/**
	 * 设置单位
	 * 
	 * @param uom
	 */
	public void setUom(String uom)
	{
		this.uom = uom;
	}

	/**
	 * 获取单价
	 * 
	 * @return
	 */
	
	public Float getUnitPrice()
	{
		return unitPrice;
	}

	/**
	 * 设置单价
	 * 
	 * @param unitprice
	 */
	public void setUnitPrice(Float unitPrice)
	{
		this.unitPrice = unitPrice;
	}

	/**
	 * 获取税率
	 * 
	 * @return
	 */
	
	public Float getTaxRate()
	{
		return taxRate;
	}

	/**
	 * 设置税率
	 * 
	 * @param taxrate
	 */
	public void setTaxRate(Float taxRate)
	{
		this.taxRate = taxRate;
	}

	/**
	 * ？？获取税后单价
	 * 
	 * @return
	 */
	
	public Integer getTaxUnitPrice()
	{
		return taxUnitPrice;
	}

	/**
	 * ？？设置税后单价
	 * 
	 * @param taxUnitPrice
	 */
	public void setTaxUnitPrice(Integer taxUnitPrice)
	{
		this.taxUnitPrice = taxUnitPrice;
	}

	/**
	 * ？？获取税后总金额
	 * 
	 * @return
	 */
	
	public Integer getTaxAmount()
	{
		return taxAmount;
	}

	/**
	 * ？？设置税后总金额
	 * 
	 * @param taxAmount
	 */
	public void setTaxAmount(Integer taxAmount)
	{
		this.taxAmount = taxAmount;
	}

	/**
	 * 获取零件唯一号
	 * 
	 * @return
	 */
	
	public String getPartUid()
	{
		return partUid;
	}

	/**
	 * 设置零件唯一号
	 * 
	 * @param partUid
	 */
	public void setPartUid(String partUid)
	{
		this.partUid = partUid;
	}

	/**
	 * 获取零件对象
	 * 
	 * @return
	 */
	
	public Part getPart()
	{
		return part;
	}

	/**
	 * 设置零件对象
	 * 
	 * @param part
	 */
	public void setPart(Part part)
	{
		this.part = part;
		// 设置对象同时设置其对象uuid
		this.partUid = part.getUuid();
	}

	/**
	 * 获取批次号
	 * 
	 * @return
	 */
	
	public String getBatchnum()
	{
		return batchnum;
	}

	/**
	 * 设置批次号
	 * 
	 * @param batchnum
	 */
	public void setBatchnum(String batchnum)
	{
		this.batchnum = batchnum;
	}

	/**
	 * 获取序号
	 * 
	 * @return
	 */
	
	public String getSn()
	{
		return sn;
	}

	/**
	 * 设置序号
	 * 
	 * @param sn
	 */
	public void setSn(String sn)
	{
		this.sn = sn;
	}

	/**
	 * 获取申请数量
	 * 
	 * @return
	 */
	
	public Float getApplyqty()
	{
		return applyqty;
	}

	/**
	 * 设置申请数量
	 * 
	 * @param applyqty
	 */
	public void setApplyqty(Float applyqty)
	{
		this.applyqty = applyqty;
	}

	/**
	 * 获取失效日期
	 * 
	 * @return
	 */
	
	public Date getInvalidDate()
	{
		return invalidDate;
	}

	/**
	 * 设置失效日期
	 * 
	 * @param invalidDate
	 */
	public void setInvalidDate(Date invalidDate)
	{
		this.invalidDate = invalidDate;
	}

	/**
	 * 获取检验日期
	 * 
	 * @return
	 */
	
	public Date getCheckupDate()
	{
		return checkupDate;
	}

	/**
	 * 设置检验日期
	 * 
	 * @param checkupDate
	 */
	public void setCheckupDate(Date checkupDate)
	{
		this.checkupDate = checkupDate;
	}

	/**
	 * 获取维护/油封日期
	 * 
	 * @return
	 */
	
	public Date getMaintenanceDate()
	{
		return maintenanceDate;
	}

	/**
	 * 设置维护/油封日期
	 * 
	 * @param maintenanceDate
	 */
	public void setMaintenanceDate(Date maintenanceDate)
	{
		this.maintenanceDate = maintenanceDate;
	}

	/**
	 * ？？获取计划物料归还日期
	 * 
	 * @return
	 */
	
	public Date getPlanReturnDate()
	{
		return planReturnDate;
	}

	/**
	 * 设置计划归还日期
	 * 
	 * @param planReturnDate
	 */
	public void setPlanReturnDate(Date planReturnDate)
	{
		this.planReturnDate = planReturnDate;
	}

	/**
	 * 获取归还日期
	 * 
	 * @return
	 */
	
	public Date getReturnDate()
	{
		return returnDate;
	}

	/**
	 * 设置归还日期
	 * 
	 * @param returnDate
	 */
	public void setReturnDate(Date returnDate)
	{
		this.returnDate = returnDate;
	}

	/**
	 * 获取归还数量
	 * 
	 * @return
	 */
	
	public Float getReturnQty()
	{
		return returnQty;
	}

	/**
	 * 设置归还数量
	 * 
	 * @param returnQty
	 */
	public void setReturnQty(Float returnQty)
	{
		this.returnQty = returnQty;
	}

	/**
	 * 获取是否完全归还
	 * 
	 * @return
	 */
	
	public Integer getIsFinishReturning()
	{
		return isFinishReturning;
	}

	/**
	 * 设置是否完全归还
	 * 
	 * @param isFinishReturning
	 */
	public void setIsFinishReturning(Integer isFinishReturning)
	{
		this.isFinishReturning = isFinishReturning;
	}

	/**
	 * 获取未全部归还原因
	 * 
	 * @return
	 */
	
	public String getNotAllReturnedReason()
	{
		return notAllReturnedReason;
	}

	/**
	 * 设置未全部归还原因
	 * 
	 * @param notAllReturnedReason
	 */
	public void setNotAllReturnedReason(String notAllReturnedReason)
	{
		this.notAllReturnedReason = notAllReturnedReason;
	}


	/**
	 * 获取未归还数量
	 * 
	 * @return
	 */
	
	public Integer getNotReturnQty()
	{
		return notReturnQty;
	}

	/**
	 * 设置未归还数量
	 * 
	 * @param notReturnQty
	 */
	public void setNotReturnQty(Integer notReturnQty)
	{
		this.notReturnQty = notReturnQty;
	}

	/**
	 * 获取拒绝类型
	 * 
	 * @return
	 */
	
	public String getRefuseType()
	{
		return refuseType;
	}

	/**
	 * 设置拒绝类型
	 * 
	 * @param refuseType
	 */
	public void setRefuseType(String refuseType)
	{
		this.refuseType = refuseType;
	}

	public String getRelationId()
	{
		return relationId;
	}

	public void setRelationId(String relationId)
	{
		this.relationId = relationId;
	}

	public Float getCurReturnQty()
	{
		return curReturnQty;
	}

	public void setCurReturnQty(Float curReturnQty)
	{
		this.curReturnQty = curReturnQty;
	}

	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}
	
	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public void setWarebin(Warebin warebin) {
		this.warebin = warebin;
	}

	public String getPartDrawingId() {
		return partDrawingId;
	}

	public void setPartDrawingId(String partDrawingId) {
		this.partDrawingId = partDrawingId;
	}

	public String getPartName() {
		return partName;
	}

	public void setPartName(String partName) {
		this.partName = partName;
	}

	public String getPartVersionId() {
		return partVersionId;
	}

	public void setPartVersionId(String partVersionId) {
		this.partVersionId = partVersionId;
	}

	public String getPartDescription() {
		return partDescription;
	}

	public void setPartDescription(String partDescription) {
		this.partDescription = partDescription;
	}

	public String getMaterialType() {
		return materialType;
	}

	public void setMaterialType(String materialType) {
		this.materialType = materialType;
	}

	public String getSupplierUid() {
		return supplierUid;
	}

	public void setSupplierUid(String supplierUid) {
		this.supplierUid = supplierUid;
	}

	public Dept getSupplier() {
		return supplier;
	}

	public void setSupplier(Dept supplier) {
		this.supplier = supplier;
	}
}